package com.ruoyi.zhmk.controller;

import java.util.List;

import com.ruoyi.zhmk.domain.request.SendCarRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhmk.domain.ZhmkCar;
import com.ruoyi.zhmk.service.IZhmkCarService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 常驻车辆Controller
 * 
 * @author ruoyi
 * @date 2021-06-25
 */
@Api("/车辆管理表")
@RestController
@RequestMapping("/zhmk/permanentCar")
public class ZhmkCarController extends BaseController
{
    @Autowired
    private IZhmkCarService zhmkCarService;

    /**
     * 查询常驻车辆列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:permanentCar:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhmkCar zhmkCar)
    {
        startPage();
        List<ZhmkCar> list = zhmkCarService.selectZhmkCarList(zhmkCar);
        return getDataTable(list);
    }

    /**
     * 导出常驻车辆列表
     */
    @PreAuthorize("@ss.hasPermi('zhmk:permanentCar:export')")
    @Log(title = "常驻车辆", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZhmkCar zhmkCar)
    {
        List<ZhmkCar> list = zhmkCarService.selectZhmkCarList(zhmkCar);
        ExcelUtil<ZhmkCar> util = new ExcelUtil<ZhmkCar>(ZhmkCar.class);
        return util.exportExcel(list, "常驻车辆数据");
    }

    /**
     * 获取常驻车辆详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhmk:permanentCar:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zhmkCarService.selectZhmkCarById(id));
    }

    /**
     * 新增常驻车辆
     */
    @PreAuthorize("@ss.hasPermi('zhmk:permanentCar:add')")
    @Log(title = "常驻车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhmkCar zhmkCar)
    {
        return toAjax(zhmkCarService.insertZhmkCar(zhmkCar));
    }

    /**
     * 修改常驻车辆
     */
    @PreAuthorize("@ss.hasPermi('zhmk:permanentCar:edit')")
    @Log(title = "常驻车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhmkCar zhmkCar)
    {
        return toAjax(zhmkCarService.updateZhmkCar(zhmkCar));
    }

    /**
     * 删除常驻车辆
     */
    @PreAuthorize("@ss.hasPermi('zhmk:permanentCar:remove')")
    @Log(title = "常驻车辆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhmkCarService.deleteZhmkCarByIds(ids));
    }

    /**
     * 车辆下发
     * @param sendCarRequest
     * @return
     */
    @ApiOperation("车辆下发")
    @PostMapping("/carSend")
    public AjaxResult carSend(@RequestBody SendCarRequest sendCarRequest){
        return zhmkCarService.carSend(sendCarRequest);
    }
}
